package com.bood.shimmer.common.enums;

import com.bood.shimmer.common.constant.ShimmerConstants;

/**
 * <p>
 * 业务异常响应码
 * </p>
 *
 * @author：bood
 * @date：2020/9/23
 */
public enum BizExceptionEnum {

    DUPLICATE_KEY(1000, "主键冲突，请重试！！！"),

    ILLEGAL_ARGUME(1010, "接口幂等性校验，请检查是否携带'" + ShimmerConstants.IDEMPOTENT_TOKEN + "'字段！！！"),
    REPETITIVE_OPERATION(1011, "接口幂等性校验，请勿重复性操作！！！");


    private Integer code;

    private String message;


    BizExceptionEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }


    public Integer code() {
        return this.code;
    }

    public String message() {
        return this.message;
    }

    public static String getMessage(String name) {
        for (BizExceptionEnum item : BizExceptionEnum.values()) {
            if (item.name().equals(name)) {
                return item.message;
            }
        }
        return name;
    }

    public static Integer getCode(String name) {
        for (BizExceptionEnum item : BizExceptionEnum.values()) {
            if (item.name().equals(name)) {
                return item.code;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.name();
    }

}
